<template>
  <div class="loginClass">
      <el-form :model="users" label-width="100px" class="demo-ruleForm">
          <el-form-item label="账号：">
            <el-input v-model="users.userName"></el-input>
          </el-form-item>
        <el-form-item label="密码：">
          <el-input v-model="users.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round  @click="checkLogin()">登录</el-button>
        </el-form-item>
      </el-form>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      users:{}
    }
  },
  methods:{
    checkLogin:function (){
        this.$http.post("/goods/checkLogin",this.users).then((resp)=>{
          // console.log(resp);
          if (resp.data.code == 20000){
              this.$message.success("登录成功！");

              //存放token
            window.sessionStorage.setItem("token",resp.data.data);
            this.$router.push("/goodsList")
          }else{
            this.$message.error("用户名或者密码错误！");
            this.users = {} ;
          }
        })
    },
  }
}
</script>

<style scoped>
  .loginClass{
    width: 450px;
    height: 312px;
    background-color: white;
    position: absolute;
    top:25% ;
    left:50% ;
    transform: translate(-50%);
    border-radius: 5px;
  }
</style>
